/**
    Copyright (C) 2012 Guido Ludwig

    This file is part of JATT.
	http://code.google.com/p/jatt/

    JATT is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.guidoludwig.jatt.util;

import java.io.File;
import java.io.FilenameFilter;

public class AudioFilter implements FilenameFilter {

	public static FilenameFilter INSTANCE = new AudioFilter();

	// private static final MimetypesFileTypeMap map = new
	// MimetypesFileTypeMap();
	//
	// private static final String MIME_TYPE_MP3 = "audio/mpeg";
	// private static final String MIME_TYPE_FLAC = "audio/flac";
	// private static final String MIME_TYPE_OGG = "audio/ogg";
	//
	private static final String EXTENSION_MP3 = ".mp3";
	private static final String EXTENSION_FLAC = ".flac";
	private static final String EXTENSION_OGG = ".ogg";

	private AudioFilter() {
		// NO
	}

	@Override
	public boolean accept(File file, String name) {
		if (file == null || name == null) {
			return false;
		}
		String lower = name.toLowerCase();
		return lower.endsWith(EXTENSION_FLAC) || lower.endsWith(EXTENSION_MP3)
				|| lower.endsWith(EXTENSION_OGG);
		// says application/octet-stream for mp3 ?
		// String mimeType = map.getContentType(file);
		// System.out.println(mimeType);
		// return MIME_TYPE_FLAC.equals(mimeType)
		// || MIME_TYPE_MP3.equals(mimeType)
		// || MIME_TYPE_OGG.equals(mimeType);

	}

}